package com.app.qbake.module.square.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.wind.base.adapter.BaseRecyclerAdapter;
import com.wind.data.publish.bean.Category;
import com.app.qbake.R;
import com.app.qbake.module.square.activity.SearchGoodsListActivity;

public class CategoryAdapter extends BaseRecyclerAdapter<Category,CategoryAdapter.ViewHolder> {


    public CategoryAdapter(Activity activity, int layoutRes) {
        super(activity, layoutRes);
    }

    @Override
    public ViewHolder onCreateViewHolder(View v) {
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final Category item= getItem(position);
        holder.tv_cate_name.setText(item.getZh_title());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchGoodsListActivity.SearchInfo searchInfo=new SearchGoodsListActivity.SearchInfo();
                searchInfo.categoryId=item.getId();
                searchInfo.keywords=item.getZh_title();
                SearchGoodsListActivity.start(mActivity,searchInfo);
                if (listener!=null)
                    listener.onItemClick(position);
            }
        });
    }


    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_cate_name;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_cate_name=itemView.findViewById(R.id.tv_cate_name);
        }
    }


    private OnItemClickListener listener;
    public void setOnItemClickListener(OnItemClickListener listener){
        this.listener=listener;
    }
    public interface OnItemClickListener{
        void onItemClick(int position);
    }
}
